package com.keye.model.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

import com.keye.model.domain.User;

@Repository("userDao")
public interface UserDao {
	
	@Results(value = {  
            @Result(id = true, property = "userId", column = "USERID"),  
            @Result(property = "departmentId", column = "DEPARTMENTID", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "userName", column = "USERNAME", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "password", column = "PASSWORD", javaType = String.class, jdbcType = JdbcType.VARCHAR)})
	@Select("SELECT USERID,DEPARTMENTID,USERNAME,PASSWORD FROM sys_user WHERE USERNAME=#{userName}")
	User selectByUserName(@Param("userName")String userName);

	@Results(value = {  
            @Result(id = true, property = "userId", column = "USERID"),  
            @Result(property = "departmentId", column = "DEPARTMENTID", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "userName", column = "USERNAME", javaType = String.class, jdbcType = JdbcType.VARCHAR),
            @Result(property = "password", column = "PASSWORD", javaType = String.class, jdbcType = JdbcType.VARCHAR)})
	@Insert("insert into sys_user (USERID,DEPARTMENTID,USERNAME,PASSWORD) values "
			+ "(#{user.userId},#{user.departmentId},#{user.userName},#{user.password})")
	int insert(@Param("user")User user);
}
